package cn.wolfcode.luowowo2.mgrsite.web.job;

import cn.wolfcode.luowowo2.article.domain.StrategyDetail;
import cn.wolfcode.luowowo2.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo2.article.vo.StrategyStatisVO;
import cn.wolfcode.luowowo2.cache.prefix.StrategyStatisKeyPrefix;
import cn.wolfcode.luowowo2.cache.service.IStrategyStatisRedisService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Albert on 2019/7/13.
 */
//@Component
public class RedisDataPersistenceJob {
    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyStatisRedisService strategyStatisRedisService;
    //下面的注解表示定时执行,每10秒执行一次
    @Scheduled(cron = "1/10 * * * * ?" )
    public void redisDataPersistence(){
        String pattern = StrategyStatisKeyPrefix.STRATEGY_STATIS_VO.getPrefix()+":*";
        List<StrategyStatisVO> list = strategyStatisRedisService.listVO(pattern);
        for (StrategyStatisVO vo : list) {
            strategyDetailService.updateRedisVO(vo);
        }
        System.out.println("saved");
    }
}
